<!DOCTYPE html>
<html lang="en">
<head>
    <meta  http-equiv="content-type" content="text/html" charset="utf-8"/>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" charset="UTF-8" src="test.js" ></script>
    <script type="text/javascript">
      //模拟java中的Map
      //  var obj = new Object();//实际就是Object方法
        function Map(){
            var obj = {};
            this.put = function(key,value){
                obj[key] = value;  //把键值对绑定到obj对象上
            }

            this.get = function(key){
                if(obj[key] || obj[key]===0 || obj[key] === false){//此处应当严谨 ，当obj[key]为0或者false时，会走else
                    return obj[key];
                }else
                    return null;
            }

            this.remove=function(key){
                if(obj[key] || obj[key]===0 || obj[key] === false){
                   delete obj[key];
                }
            }

            this.size = function(){
                var count = 0;
                for(var i in obj){
                    count++;
                }
                return count;
            }

            this.eachMap = function(fn){//此处使用了回调函数
                for(var attr in obj){
                    fn(attr,obj[attr]);
                }
            }
      }

      var m = new Map();
      m.put('01','abc');
      m.put('02',120);
      m.put('03',true);
      m.put('04',new Date());

      m.eachMap(function(key,value){
          alert(key + ": "+ value);
      })

    </script>
</head>
<body>

</body>
</html>